package com.ruoyi.project.dj.controller;

import java.util.List;

import com.ruoyi.common.utils.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dj.domain.DjStudyDynamic;
import com.ruoyi.project.dj.service.IDjStudyDynamicService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 学习动态Controller控制器
 *
 * @author ruoyi
 * @date 2025-09-15
 */
@Controller
@RequestMapping("/dj/study/dynamic")
public class DjStudyDynamicController extends BaseController
{
    private String prefix = "dj/study/dynamic";

    @Autowired
    private IDjStudyDynamicService djStudyDynamicService;

    @RequiresPermissions("dj:study:dynamic:view")
    @GetMapping()
    public String dynamic()
    {
        return prefix + "/partyMemberEvaluation";
    }

    /**
     * 查询学习动态列表
     */
    @RequiresPermissions("dj:study:dynamic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjStudyDynamic djStudyDynamic)
    {
        startPage();
        List<DjStudyDynamic> list = djStudyDynamicService.selectDjStudyDynamicList(djStudyDynamic);
        return getDataTable(list);
    }

    /**
     * 导出学习动态列表
     */
    @RequiresPermissions("dj:study:dynamic:export")
    @Log(title = "学习动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjStudyDynamic djStudyDynamic)
    {
        List<DjStudyDynamic> list = djStudyDynamicService.selectDjStudyDynamicList(djStudyDynamic);
        ExcelUtil<DjStudyDynamic> util = new ExcelUtil<DjStudyDynamic>(DjStudyDynamic.class);
        return util.exportExcel(list, "学习动态");
    }

    /**
     * 新增学习动态
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学习动态
     */
    @RequiresPermissions("dj:study:dynamic:add")
    @Log(title = "学习动态", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjStudyDynamic djStudyDynamic)
    {
        return toAjax(djStudyDynamicService.insertDjStudyDynamic(djStudyDynamic));
    }

    /**
     * 修改学习动态
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DjStudyDynamic djStudyDynamic = djStudyDynamicService.selectDjStudyDynamicById(id);
        mmap.put("djStudyDynamic", djStudyDynamic);
        return prefix + "/edit";
    }

    /**
     * 修改保存学习动态
     */
    @RequiresPermissions("dj:study:dynamic:edit")
    @Log(title = "学习动态", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjStudyDynamic djStudyDynamic)
    {
        return toAjax(djStudyDynamicService.updateDjStudyDynamic(djStudyDynamic));
    }

    /**
     * 删除学习动态
     */
    @RequiresPermissions("dj:study:dynamic:remove")
    @Log(title = "学习动态", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djStudyDynamicService.deleteDjStudyDynamicByIds(Convert.toLongArray(ids)));
    }
}